package com.stefanie.study.sp;

import lombok.Data;

/**
 * @author: stefanie-zy
 * @time: 2024/6/26-15:14
 * @description: 单例模式
 */
@Data
public class User {

    // 属性
    private String name;
    private Integer age;
    private String address;

    // 私有化构造方法
    private User() {
        this.name = "Stefanie-Zy";
        this.address = "陕西省西安市";
        this.age = 1;
    }

    // 私有化成员变量，成为唯一实例
    private static User user = null;

    // 对外提供方法
    public static User getSingleton() {
        if (user == null) {
            user = new User();
        }
        return user;
    }
}
